import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.countKDistanceSubstring("pqpqs", 2));

        System.out.println(solution.maxOfAllMin(5, Arrays.asList(2,3,7,1,8), 3));
    }

    int countKDistanceSubstring(String inputString, int num) {
        if (num <= 0) {
            return 0;
        }

        int count = 0;
        for (int i = 0; i < inputString.length(); i++) {
            Set<Character> characterSet = new HashSet<>();
            for (int j = i; j < inputString.length(); j++) {
                if (characterSet.size() < num) {
                    characterSet.add(inputString.charAt(j));
                } else if (characterSet.size() == num) {
                    count++;
                    characterSet.add(inputString.charAt(j));
                } else {
                    break;
                }
            }
            if ((characterSet.size() == num)) {
                count++;
            }
        }
        return count;
    }


    int maxOfAllMin(int numComputer, List<Integer> hardDiskSpace, int segmentLength) {
        if (numComputer <= 0 || segmentLength <= 0) {
            return 0;
        }

        if (numComputer <= segmentLength) {
            return min(hardDiskSpace);
        }

        if (segmentLength == 1) {
            return max(hardDiskSpace);
        }

        int maxMin = Integer.MIN_VALUE;
        for (int i = 0; i <= numComputer - segmentLength; i++) {
            List<Integer> subList = hardDiskSpace.subList(i, i + segmentLength);
            System.out.println(subList);
            int min = min(subList);

            if (maxMin < min) {
                maxMin = min;
            }
        }

        return maxMin;
    }

    public int min(List<Integer> list) {
        int min = Integer.MAX_VALUE;
        for (Integer integer : list) {
            if (integer < min) {
                min = integer;
            }
        }
        return min;
    }

    public int max(List<Integer> list) {
        int max = Integer.MIN_VALUE;
        for (Integer integer : list) {
            if (integer > max) {
                max = integer;
            }
        }
        return max;
    }

//    string LongestWord (List<string> listOfWords) {
//        if (listOfWords.size() == 0) {
//            return null;
//        }
//        string longest = null;
//        for (int i = 0; i < listOfWords.size(); i++) {
//            if (listOfWords == null || longest.length() < listOfWords.get(i).length()) {
//                longest = listOfWords.get(i);
//            }
//        }
//        return longest;
//    }


}
